package io.mya.modules.sys.dao;

import io.mya.modules.sys.vo.CandyUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Created by ShawnShoper on 2017/5/24.
 */
@Mapper
public interface UserMapper {
    @Select("select id,username,mail,phone from candyuser where promoterId = ${id} and status = 1")
    List<CandyUser> getSubUser(@Param("id") long id);

    @Select("select id,username,mail,phone from candyuser where id = ${id} and status = 1")
    CandyUser getUser(@Param("id") long id);

    @Select("select count(0) from candyuser where promoterId = ${id} and status = 1")
    Integer getSubUserCount();

    @Select("select promoterId from candyuser where id = ${currUser} and status = 1")
    Long getPrevPrometor(@Param("currUser") Long currUser);

    @Update("update candyuser set candycount=${bound}+candycount where id =${userId}")
    void addBonus(@Param("userId") Long userId, @Param("bound") int bound);

    @Select("select count from candybonus where lv = ${lv}")
    int getBonusCount(@Param("lv")int lv);


    @Select("select SUM(candycount) from candyuser where status = 1")
    int getUserCandyCount();
}

